package com.yanqu.road.server.cross3server.cmd.luckydraw;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.LuckyDrawProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manger.ServerListMgr;
import com.yanqu.road.server.protocol.AgentProtocol;
import com.yanqu.road.server.protocol.Cross3Protocol;
import com.yanqu.road.utils.ConfigHelper;
import com.yanqu.road.utils.YanQuMessageUtils;

import java.util.List;

@Cmd(code = Cross3Protocol.C3_LUCKY_DRAW_TRANSFER_RECORD, desc = "")
public class Cross3LuckyDrawTransferRecordCmd extends CrossCommand {

    private List<Long> idList;
    private LuckyDrawProto.LuckyDrawSyncRecordRespMsg msg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        LuckyDrawProto.ChannelLuckyDrawSyncRecordRespMsg respMsg = LuckyDrawProto.ChannelLuckyDrawSyncRecordRespMsg.parseFrom(packet.getBytes());
        idList = respMsg.getServerIdList();
        msg = respMsg.getMsg();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        int channelId = ConfigHelper.getInt("channelId");
        for (long serverId : idList) {
            if (ServerListMgr.getChannelId(serverId) == channelId) {
                YanQuMessage message = YanQuMessageUtils.buildMessage(AgentProtocol.A_LUCKY_DRAW_TRANSFER_RECORD, msg.toBuilder());
                MessageHelper.sendPacket(serverId, 0, message);
            }
        }
    }

    @Override
    public void sendData() {

    }
}
